<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>


    let obj = {
      name: '张三',
      age: 18,
      gender: '男'
    }

    // let arr = ['张三', 18, '男']

    // for(let i = 0;i<arr.length;i++){
    //   document.write(arr[i])
    // }


    // for (let k in arr) {
    //   console.log(arr[k]) '0'  '1' '2'
    //   console.log(k)  //不推荐 索引是字符串类型
    // }


    //遍历对象 for in
    for (let k in obj) {
      // console.log(k) // 'name'  'age' 'gender'
      // console.log(obj.age)
      // console.log(k.age)
      // console.log(obj.k)
      // console.log(obj.'name')
      // console.log(obj['name'])
      // console.log(obj['age'])
      // console.log(obj['gender'])

      console.log(obj[k])


    }





  </script>
</body>

</html>